package com.bluetrum.devicemanager.cmd.request;

import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;

public final class AncRequest extends TlvRequest {

    public static final byte ANC_MODE                   = 1;
    public static final byte ANC_NC_LEVEL               = 2;
    public static final byte ANC_TRANSPARENCY_LEVEL     = 3;
    public static final byte ANC_FADE                   = 4;

    public static final byte ANC_MODE_OFF               = 0x00;
    public static final byte ANC_MODE_ON                = 0x01;
    public static final byte ANC_MODE_TRANSPARENCY      = 0x02;

    private final Byte ancMode;
    private final Byte ncLevel;
    private final Byte transparencyLevel;
    private final Boolean enableFade;

    private AncRequest(@Nullable Byte ancMode,
                       @Nullable Byte ncLevel,
                       @Nullable Byte transparencyLevel,
                       @Nullable Boolean enableFade) {
        super(COMMAND_ANC);
        this.ancMode = ancMode;
        this.ncLevel = ncLevel;
        this.transparencyLevel = transparencyLevel;
        this.enableFade = enableFade;

        // invoke before use getPreGeneratedPayload()
        generatePayload();
    }

    public static AncRequest modeRequest(byte ancMode) {
        return new AncRequest(ancMode, null, null, null);
    }

    public static AncRequest ncLevelRequest(byte ncLevel) {
        return new AncRequest(null, ncLevel, null, null);
    }

    public static AncRequest transparencyLevel(byte transparencyLevel) {
        return new AncRequest(null, null, transparencyLevel, null);
    }

    public static AncRequest fadeRequest(boolean enableFade) {
        return new AncRequest(null, null, null, enableFade);
    }

    @Override
    protected Map<Byte, Object> getTlvObjectMap() {
        return new HashMap<Byte, Object>(){{
            put(ANC_MODE, ancMode);
            put(ANC_NC_LEVEL, ncLevel);
            put(ANC_TRANSPARENCY_LEVEL, transparencyLevel);
            put(ANC_FADE, enableFade);
        }};
    }

    @Override
    public byte[] getPayload() {
        return getPreGeneratedPayload();
    }
}
